<!-- by 7527189 2 0 -->
<template>
  <a-row :gutter="10">
    <!-- <a-col :md="24"> -->
    <a-col :md="4" :sm="24" :style="{height:treeHeight+'px'}" style="background: #fff;padding-left:16px;overflow-y: scroll;" >
      <a-card :bordered="false" >
        <div   >
          <!-- 树-->
          <a-col :md="10" :sm="24">
            <template>
              <a-dropdown :trigger="[this.dropTrigger]" @visibleChange="dropStatus">
                <span style="user-select: none">
                  <a-tree @select="onSelect" :treeData="categoryTree" :checkStrictly="checkStrictly"
                    :expandedKeys="iExpandedKeys" :autoExpandParent="true" @expand="onExpand" />
                </span>
              </a-dropdown>
            </template>
          </a-col>
        </div>
      </a-card>
    </a-col>
    <a-col :md="20" :sm="24">
      <a-card :style="cardStyle" :bordered="false" ref="dataMain">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('commodityManagement.category')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-tree-select style="width:100%" :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
                  :filterTreeNode="filterTreeNode"
                  showSearch
                    allow-clear :treeData="categoryTree" v-model="queryParam.categoryId"
                    :placeholder="$t('commodityManagement.pleaseCategory')">
                  </a-tree-select>
                </a-form-item>
              </a-col>
              <!-- 关键词 -->
              <a-col :md="6" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('commodityManagement.pleaseQuery')" v-model="queryParam.barCode"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('basicInformation.name')" v-model="queryParam.name"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('warehouseManagement.Specification')"
                    v-model="queryParam.standard"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('manuManagement.Contactus')" v-model="queryParam.model"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('commodityManagement.batchNumber')" v-model="queryParam.color"></a-input>
                </a-form-item>
              </a-col>
              <!-- <a-col :md="6" :sm="24">
                <a-form-item :label="$t('commodityManagement.qualityPeriod')" :labelCol="labelCol"
                  :wrapperCol="wrapperCol">
                  <a-input-number style="width: 100%" :placeholder="$t('commodityManagement.pleaseLifeQuery')"
                    v-model="queryParam.expiryNum"></a-input-number>
                </a-form-item>
              </a-col> -->
              <!-- <a-col :md="6" :sm="24">
                  <a-form-item label="颜色" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input placeholder="请输入颜色查询" v-model="queryParam.color"></a-input>
                  </a-form-item>
                </a-col> -->
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">{{ $t('commodityManagement.query') }}</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">{{ $t('commodityManagement.reset')
                  }}</a-button>
        
                  <a @click="handleToggleSearch" style="margin-left: 8px">
                    {{ toggleSearchStatus ? $t('commodityManagement.putAway') : $t('commodityManagement.open') }}
                    <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                  </a>
                </a-col>
              </span>
              <template v-if="toggleSearchStatus">

                <!-- <a-col :md="6" :sm="24">
                    <a-form-item label="基础重量" :labelCol="labelCol" :wrapperCol="wrapperCol">
                      <a-input-number style="width: 100%" placeholder="请输入基础重量查询" v-model="queryParam.weight"></a-input-number>
                    </a-form-item>
                  </a-col> -->

                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('commodityManagement.state')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-select :placeholder="$t('commodityManagement.pleaseStatus')" v-model="queryParam.enabled">
                      <a-select-option value="1">{{ $t('commodityManagement.enable') }}</a-select-option>
                      <a-select-option value="0">{{ $t('commodityManagement.disable') }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <!-- <a-col :md="6" :sm="24">
                    <a-form-item label="序列号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                      <a-select placeholder="有无序列号" v-model="queryParam.enableSerialNumber">
                        <a-select-option value="1">有</a-select-option>
                        <a-select-option value="0">无</a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-col> -->
                <!-- <a-col :md="6" :sm="24">
                    <a-form-item label="批号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                      <a-select placeholder="有无批号" v-model="queryParam.enableBatchNumber">
                        <a-select-option value="1">有</a-select-option>
                        <a-select-option value="0">无</a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-col> -->
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('commodityManagement.remarks')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input :placeholder="$t('commodityManagement.pleaseComments')"
                      v-model="queryParam.remark"></a-input>
                  </a-form-item>
                </a-col>
              </template>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <a-button v-if="btnEnableList.indexOf(1) > -1" @click="handleAdd" type="primary" icon="plus">{{
              $t('commodityManagement.newlyAdded')
          }}</a-button>
          <a-upload name="file" v-if="btnEnableList.indexOf(3) > -1" :showUploadList="false" :multiple="false" :headers="tokenHeader" :beforeUpload="beforeMaterialUpload"
            :action="importExcelUrl" @change="handleImportExcel">
            <a-popover :title="$t('commodityManagement.formTemplate')">
              <template slot="content">
                <p><a target="_blank" href="/doc/goods_template.xls"><b>{{ $t('commodityManagement.productDownload')
                }}</b></a></p>
              </template>
              <a-button type="primary" icon="import">{{ $t('commodityManagement.import') }}</a-button>
            </a-popover>
          </a-upload>
          <a-button type="primary" icon="download" v-if="btnEnableList.indexOf(3) > -1"
            @click="handleExportXls($t('commodityManagement.commodityInformation'))">{{ $t('commodityManagement.export')
            }}</a-button>
          <a-dropdown v-if="btnEnableList.indexOf(1) > -1">
            <a-menu slot="overlay">
              <a-menu-item key="1" v-if="btnEnableList.indexOf(1) > -1" @click="batchDel"><a-icon type="delete" />{{
                  $t('commodityManagement.delete')
              }}</a-menu-item>
              <a-menu-item key="2" v-if="btnEnableList.indexOf(1) > -1" @click="batchSetStatus(true)"><a-icon
                  type="check-square" />{{ $t('commodityManagement.enable') }}</a-menu-item>
              <a-menu-item key="3" v-if="btnEnableList.indexOf(1) > -1" @click="batchSetStatus(false)"><a-icon
                  type="close-square" />{{ $t('commodityManagement.disable') }}</a-menu-item>
              <a-menu-item key="4" v-if="btnEnableList.indexOf(1) > -1" @click="batchEdit()"><a-icon type="edit" />{{
                  $t('commodityManagement.batchEditing')
              }}</a-menu-item>
              <!-- <a-menu-item key="5" @click="batchSetMaterialCurrentStock()"><a-icon
                  type="stock" />{{ $t('commodityManagement.correctInventory') }}</a-menu-item> -->
              <a-menu-item key="6" v-if="btnEnableList.indexOf(1) > -1" @click="showModual()"><a-icon
                  type="stock" />{{ $t('commodityManagement.confirmSellingPrice') }}</a-menu-item>
              <a-menu-item key="7" v-if="btnEnableList.indexOf(1) > -1" @click="showUpdateModual()"><a-icon type="to-top" />{{ $t('commodityManagement.updateDopet') }}</a-menu-item>
            </a-menu>
            <a-button>
              {{ $t('commodityManagement.batchOperation') }} <a-icon type="down" />
            </a-button>
          </a-dropdown>
          <a-button  v-if="btnEnableList.indexOf(1) > -1"  @click="batchSetPrice">{{ $t('setailManagement.batchModifyPrice') }}</a-button>

          <a-popover trigger="click" placement="right">
            <template slot="content">
              <a-checkbox-group @change="onColChange" v-model="settingColumns" :defaultValue="settingColumns">
                <a-row style="width: 500px">
                  <template v-for="(item, index) in defColumns">
                    <template>
                      <a-col :span="8">
                        <a-checkbox :value="item.dataIndex">
                          <j-ellipsis :value="item.title" :length="10"></j-ellipsis>
                        </a-checkbox>
                      </a-col>
                    </template>
                  </template>
                </a-row>
              </a-checkbox-group>
            </template>
            <a-button icon="setting">{{ $t('commodityManagement.columnSettings') }}</a-button>
          </a-popover>
          <a-button v-if="btnEnableList.indexOf(1) > -1" icon="delete" @click="batchDel">{{ $t('setailManagement.delete') }}</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table ref="table" size="middle" bordered :customRow="rowClick" rowKey="id" :columns="columns"
            :dataSource="dataSource" :pagination="ipagination" :scroll="scroll" :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, columnWidth: '2%' }"
            @change="handleTableChange">
            <!-- <span slot="action" slot-scope="text, record">
                <a @click="handleEdit(record)">{{$t('commodityManagement.edit')}}</a>
                <a-divider v-if="btnEnableList.indexOf(1)>-1" type="vertical" />
                <a-popconfirm v-if="btnEnableList.indexOf(1)>-1" :title="$t('commodityManagement.areDelete')" @confirm="() => handleDelete(record.id)">
                  <a>{{$t('commodityManagement.delete')}}</a>
                </a-popconfirm>
              </span> -->
            <template slot="customRenderEnabled" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">{{ $t('commodityManagement.enable') }}</a-tag>
              <a-tag v-if="!enabled" color="orange">{{ $t('commodityManagement.disable') }}</a-tag>
            </template>
            <template slot="customRenderEnableSerialNumber" slot-scope="enableSerialNumber">
              <a-tag v-if="enableSerialNumber == 1" color="green">{{ $t('commodityManagement.have') }}</a-tag>
              <a-tag v-if="enableSerialNumber == 0" color="orange">{{ $t('commodityManagement.nothing') }}</a-tag>
            </template>
            <template slot="confirm" slot-scope="text,record">
                <a-popconfirm v-if="btnEnableList.indexOf(1)>-1" :title="+record.enableBatchNumber? $t('commodityManagement.cancleSellingPrice'):$t('commodityManagement.confirmSellingPrice')" @confirm="() => handleConfirm(record)">
                  <a-button style="border:none;color: #409eff;" type="text" primary :loading="record.enableBatchNumberLoading">{{+record.enableBatchNumber? $t('inPrint.cancel') : $t('otherJS.confirm') }}</a-button>
                </a-popconfirm>
            </template>
            
            <!-- <template slot="customRenderEnableBatchNumber" slot-scope="enableBatchNumber">
                <a-tag v-if="enableBatchNumber==1" color="green">{{$t('commodityManagement.have')}}</a-tag>
                <a-tag v-if="enableBatchNumber==0" color="orange">{{$t('commodityManagement.nothing')}}</a-tag>
              </template> -->
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <material-modal ref="modalForm" :categoryId="queryParam.categoryId" @ok="modalFormOk"></material-modal>
        <batch-set-info-modal ref="batchSetInfoModalForm" @ok="modalFormOk"></batch-set-info-modal>
        <batch-set-price-modal ref="priceModalForm" @ok="batchSetPriceModalFormOk"></batch-set-price-modal>
        <batch-update-lesses ref="lessesModalForm" @ok="batchUpdateFormOk"></batch-update-lesses>
      </a-card>
    </a-col>
    <!-- </a-col> -->
  </a-row>
</template>
<script>
import MaterialModal from './modules/MaterialModal'
import BatchSetInfoModal from './modules/BatchSetInfoModal'
import BatchSetPriceModal from './modules/BatchSetPriceModal'
import BatchUpdateLesses from './modules/BatchUpdateLesses'
import { queryMaterialCategoryTreeList, showPurchase,batchUpdateSalesPrice } from '@/api/api'
import { postAction } from '@/api/manage'
import { getMpListShort } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import JDate from '@/components/jeecg/JDate'
import { Modal } from 'ant-design-vue';
import Vue from 'vue'
import { getAction,deleteAction } from '../../api/manage'

export default {
  name: "MaterialList",
  provide() {
    return {
      loadData1: this.loadData
    }
  },
  mixins: [JeecgListMixin],
  components: {
    MaterialModal,
    BatchSetInfoModal,
    BatchSetPriceModal,
    BatchUpdateLesses,
    JEllipsis,
    JDate
  },
  data() {
    return {
      allTreeKeys: [],
      categoryTree: [],
      checkedKeys: [],
      checkStrictly: true,
      visible:false,
      iExpandedKeys: [],
      mPropertyListShort: '',
      model: {},
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      selectedKeys: [],
      dropTrigger: '',
      treeHeight:'',

      // 查询条件
      queryParam: {
        color: '',
        model: '',
        standard: '',
        categoryId: '',
        // materialParam: '',
        barCode: '',
        name: '',
        color: '',
        weight: '',
        expiryNum: '',
        enabled: '',
        enableSerialNumber: '',
        enableBatchNumber: '',
        remark: '',
        mpList: getMpListShort(Vue.ls.get('materialPropertyList'))  //扩展属性
      },
      ipagination: {
        pageSizeOptions: ['10', '20', '30', '100', '200']
      },
      // 实际表头
      columns: [],
      // 初始化设置的表头
      settingColumns: ['confirm', 'name', 'standard','supplier', 'model', 'color', 'categoryName', 'unit', 'stock',
       'commodityDecimal', 'wholesaleDecimal', 'lowDecimal', 'enabled', 'enableSerialNumber', 'enableBatchNumber', 'action'],
      // 默认的列
      defColumns: [
        {
          title:this.$t('commodityManagement.confirmSellingPrice'),
          dataIndex: 'confirm',
          align:"center",
          width: 100,
          scopedSlots: { customRender: 'confirm' },
        },
        
        {
          title: this.$t('commodityManagement.batchNumber'), dataIndex: 'color', align: "center", width: 80,
          // scopedSlots: { customRender: 'customRenderEnableBatchNumber' }
        },
        { title: this.$t('commodityManagement.name'), dataIndex: 'name' },
        { title: this.$t('commodityManagement.specifications'), dataIndex: 'standard' },
        { title: this.$t('popup.defaultSupplier'), dataIndex: 'supplier',width: 180, },
        
        { title: this.$t('commodityManagement.model'), dataIndex: 'model',width:60 },
        // {title: '颜色', dataIndex: 'color'},
        { title: this.$t('commodityManagement.category'), dataIndex: 'categoryName', width: 100, ellipsis: true },
        // { title: this.$t('commodityManagement.extendedInformation'), dataIndex: 'materialOther', width: 100, ellipsis: true },
        {
          title: this.$t('commodityManagement.company'), dataIndex: 'unit', width: 100, ellipsis: true,
          customRender: function (t, r, index) {
            if (r) {
              // let name = t?t:r.unitName
              let name = r.unitName
              if (r.sku) {
                return name + '[SKU]';
              } else {
                return name;
              }
            }
          }
        },
        // {title: '基础重量', dataIndex: 'weight', width: 80},
        { title: this.$t('commodityManagement.qualityPeriod'), dataIndex: 'expiryNum', width: 60 },
        { title: this.$t('commodityManagement.stock'), dataIndex: 'stock', width: 80 },
        { title: this.$t('commodityManagement.purchasePrice'), dataIndex: 'purchaseDecimal', width: 80 },
        { title: this.$t('commodityManagement.retailPrice'), dataIndex: 'commodityDecimal', width: 80 },
        { title: this.$t('commodityManagement.SellingPrice'), dataIndex: 'wholesaleDecimal', width: 80 },
        { title: this.$t('commodityManagement.lowestPrice'), dataIndex: 'lowDecimal', width: 80 },
        { title: this.$t('commodityManagement.remarks'), dataIndex: 'remark' },
        // { title: this.$t('commodityManagement.barCode'), dataIndex: 'mBarCode' },

        {
          title: this.$t('commodityManagement.state'), dataIndex: 'enabled', align: "center", width: 60,
          scopedSlots: { customRender: 'customRenderEnabled' }
        },
        // {title: '序列号', dataIndex: 'enableSerialNumber', align: "center", width: 60,
        //   scopedSlots: { customRender: 'customRenderEnableSerialNumber' }
        // },
        // {
        //   title:this.$t('commodityManagement.operation'),
        //   dataIndex: 'action',
        //   align:"center",
        //   width: 100,
        //   scopedSlots: { customRender: 'action' },
        // }
      ],
      url: {
        list: "/material/list",
        delete: "/material/delete",
        deleteBatch: "/material/deleteBatch",
        importExcelUrl: "/material/importExcel",
        exportXlsUrl: "/material/exportExcel",
        batchSetStatusUrl: "/material/batchSetStatus",
        batchSetMaterialCurrentStockUrl: "/material/batchSetMaterialCurrentStock"
      }
    }
  },
  created() {
    this.model = Object.assign({}, {});
    this.initColumnsSetting()
    this.loadTreeData();
  },
  mounted(){
    this.treeHeight = this.$refs.dataMain.$el.clientHeight
    console.log('this.treeHeight :>> ', this.treeHeight);
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`;
    }
  },
  methods: {
    
    filterTreeNode(input,treeNode){
        return treeNode.data.props.title.toLowerCase().includes(input.toLowerCase())
      },
    beforeMaterialUpload(){
      queryMaterialCategoryTreeList({}).then(res=>{
        if(!res || !res.length){
          this.$message.error(this.$t('commodityManagement.pleaseUploadTheGoodsCategoryFirst'))
          throw new Error('请优先上传商品分类')
        }
      })
      let params ={
        search: {"supplier":"","type":"供应商","telephone":"","phonenum":""},
        column: 'createTime',
        order: 'desc',
        field: 'id,supplier,contacts,telephone,phoneNum,email,beginNeedPay,allNeedPay,taxRate,enabled',
        currentPage: 1,
        pageSize: 10
      }
      getAction('/supplier/list',params).then(res=>{
        if(res.code == 200){
          if(!res.data.rows.length){
            this.$message.error(this.$t('commodityManagement.pleaseUploadSupplierFirst'))
            throw new Error('请优先上传供应商')
          }
        }else{
          this.$message.error(this.$('commodityManagement.supplierDataError'))
          throw new Error('供应商数据异常')
        }
      })


    },
    rowClick(record, index) {
      return {
        on: {
          click: () => {
          },
          dblclick: () => {
            // console.log('双击了我')
            this.handleEdit(record)
          },
        }
      }
    },
    //根据类别id加载类别树
    getTreeByParams(params) {
      queryMaterialCategoryTreeList(params).then((res) => {
        if (res) {
          this.treeData = []
          for (let i = 0; i < res.length; i++) {
            this.treeData.push(res[i])
          }
        }
      })
    },
    expandAll() {
      this.iExpandedKeys = this.allTreeKeys
    },
    onExpand(expandedKeys) {
      console.log('onExpand', expandedKeys)
      this.iExpandedKeys = expandedKeys
    },
    // 右键操作方法
    rightHandle(node) {
      this.dropTrigger = 'contextmenu'
      console.log(node.node.eventKey)
      this.rightClickSelectedKey = node.node.eventKey
      this.rightClickSelectedOrgCode = node.node.dataRef.orgCode
    },
    onCheck(checkedKeys, info) {
      console.log('onCheck', checkedKeys, info)
      this.hiding = false
      //this.checkedKeys = checkedKeys.checked
      // <!---- author:os_chengtgen -- date:20190827 --  for:切换父子勾选模式 =======------>
      if (this.checkStrictly) {
        this.checkedKeys = checkedKeys.checked;
      } else {
        this.checkedKeys = checkedKeys
      }
      // <!---- author:os_chengtgen -- date:20190827 --  for:切换父子勾选模式 =======------>
    },
    
    batchDel: function () {
      if (!this.url.deleteBatch) {
        this.$message.error('请设置url.deleteBatch属性!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning(this.$t('otherJS.checkPieceOfData'))
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        this.$confirm({
          title: this.$t('commodityManagement.confirmDeletion'),
          content: this.$t('commodityManagement.whetherDelCheckedData'),
          onOk: function () {
            that.loading = true
            deleteAction(that.url.deleteBatch, { ids: ids })
              .then(res => {
                if (res.code === 200) {
                  that.loadData()
                  that.onClearSelected()
                } else {
                  that.$message.warning(res.data.message)
                }
              })
              .finally(() => {
                that.loading = false
              })
          }
        })
      }
    },
    onSelect(selectedKeys, e) {
      this.hiding = false
      let record = e.node.dataRef
      let params = {};
      params.id = record.id;
      this.getTreeByParams(params)
      this.queryParam = {}
      this.$set(this.queryParam,'categoryId',params.id)
      this.searchQuery()
    },
    // 右键点击下拉框改变事件
    dropStatus(visible) {
      if (visible == false) {
        this.dropTrigger = ''
      }
    },
    //加载初始化列
    initColumnsSetting() {
      let columnsStr = Vue.ls.get('materialColumns')
      
      if (columnsStr && columnsStr.indexOf(',') > -1) {
              this.settingColumns = columnsStr.split(',')
            }
      showPurchase().then((res) => {
        const index = this.defColumns.findIndex(v=>v.dataIndex === 'purchaseDecimal')
        const indexStr = this.settingColumns.findIndex(v=>v.dataIndex === 'purchaseDecimal')
        if (res == true) {
          if (index === -1) {
            this.defColumns.splice(10,0,{ dataIndex: 'purchaseDecimal', title: this.$t('commodityManagement.purchasePrice'),width: 80 })
          }
          if(indexStr === -1){
            this.settingColumns.splice(10,0,'purchaseDecimal')
          }
        }else{
          if(index > -1){
            this.defColumns.splice(index,1)
          }
          
          if(indexStr > 1){
            this.settingColumns.splice(indexStr,1)
          }
        }
        this.columns = this.defColumns.filter(item => {
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
      })
      
    },
    showModual(){
      this.$confirm({
          title: '确认操作',
          content: this.$t('commodityManagement.confirmSellingPrice') + '?',
          onOk:()=>this.handleConfirm()
      })
    },
    handleConfirm(record){
      let ids = "";
      if(record && record.id){
        // this.$message.error(`修改的数据为${record.id}`)
        ids = record.id
        this.$set(record,'enableBatchNumberLoading',true)
      }else{
        // 多选
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning(this.$t('commodityManagement.pleaseRecord'));
          return;
        } else {

          for (let a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
        }
      }
      let enableBatchNumber = '1'
      // 多选默认为1，单选取反
      if(record && +record.enableBatchNumber){
        enableBatchNumber = '0'
      }
      // request
      batchUpdateSalesPrice({ids:ids,enableBatchNumber:enableBatchNumber}).then(res=>{
        if(res.code === 200){
          this.loadData(1)
          this.$message.success(this.$t('systemManagement.success'));
        }else{
          this.$message.error(res.data);
        }
        if(record){
          this.$set(record,'enableBatchNumberLoading',false)

        }
      })
    },
    //根据类别id加载类别树
    getTreeByParams(params) {
      this.loading = true;
      queryMaterialCategoryTreeList(params).then((res) => {
        if (res) {
          this.treeData = []
          for (let i = 0; i < res.length; i++) {
            this.treeData.push(res[i])
          }
          this.loading = false;

        } else {
          this.columns.forEach((item, index) => {
            if (item.dataIndex == 'purchaseDecimal') {
              this.columns.splice(index, 1)
            }
          });
        }
      })
    },
    //列设置更改事件
    onColChange(checkedValues) {
      this.columns = this.defColumns.filter(item => {
        if (checkedValues.includes(item.dataIndex)) {
          return true
        }
        return false
      })
      let columnsStr = checkedValues.join()
      Vue.ls.set('materialColumns', columnsStr)
    },
    loadTreeData() {
      let that = this;
      let params = {};
      params.id = '';
      queryMaterialCategoryTreeList(params).then((res) => {
        if (res) {
          that.categoryTree = [];
          for (let i = 0; i < res.length; i++) {
            let temp = res[i];
            that.categoryTree.push(temp);
            that.setThisExpandedKeys(temp)
          }
        }
      })
    },
    setThisExpandedKeys(node) {
      if (node.children && node.children.length > 0) {
        this.iExpandedKeys.push(node.key)
        for (let a = 0; a < node.children.length; a++) {
          this.setThisExpandedKeys(node.children[a])
        }
      }
    },
    batchSetMaterialCurrentStock() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning(this.$t('commodityManagement.pleaseRecord'));
      } else {
        let ids = "";
        for (let a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        let that = this;
        this.$confirm({
          title: this.$t('commodityManagement.confirmOperation'),
          content: this.$t('commodityManagement.operateSelected'),
          onOk: function () {
            that.loading = true;
            postAction(that.url.batchSetMaterialCurrentStockUrl, { ids: ids }).then((res) => {
              if (res.code === 200) {
                that.$message.info(this.$t('commodityManagement.inventorySucceeded'));
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.data.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }
    },
    
    batchUpdateFormOk(){
      this.loadData(1)
    },
    batchSetPriceModalFormOk(price, batchType) {
      let arr = this.meTable.dataSource
      if (arr.length === 0) {
        this.$message.warning(this.$t('popup.pleaseCompanyFirst'));
      } else {
        let meTableData = []
        for (let i = 0; i < arr.length; i++) {
          let meInfo = {
            barCode: arr[i].barCode, commodityUnit: arr[i].commodityUnit, sku: arr[i].sku,
            purchaseDecimal: arr[i].purchaseDecimal, commodityDecimal: arr[i].commodityDecimal,
            wholesaleDecimal: arr[i].wholesaleDecimal, lowDecimal: arr[i].lowDecimal
          }
          if (batchType === 'purchase') {
            meInfo.purchaseDecimal = price - 0
          } else if (batchType === 'commodity') {
            meInfo.commodityDecimal = price - 0
          } else if (batchType === 'wholesale') {
            meInfo.wholesaleDecimal = price - 0
          } else if (batchType === 'low') {
            meInfo.lowDecimal = price - 0
          }
          if (arr[i].id) {
            meInfo.id = arr[i].id
          }
          meTableData.push(meInfo)
        }
        this.meTable.dataSource = meTableData
      }
    },
    batchSetPrice() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning(this.$t('commodityManagement.pleaseRecord'));
      } else {
        let ids = "";
        for (let a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        this.$refs.priceModalForm.edit(ids);
        this.$refs.priceModalForm.title = this.$t('batchModifyPrice.batchModifyPrice')
      }
    },
    showUpdateModual() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning(this.$t('commodityManagement.pleaseRecord'));
      } else {
        let ids = "";
        for (let a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        this.$refs.lessesModalForm.edit(ids,this.dataSource);
        this.$refs.lessesModalForm.url.batchUpdateUrl = '/material/batchSetMaterialTenant';
        this.$refs.lessesModalForm.title = this.$t('commodityManagement.updateDopet')
      }
    },
    batchEdit() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning(this.$t('commodityManagement.pleaseRecord'));
      } else {
        let ids = "";
        for (let a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        this.$refs.batchSetInfoModalForm.edit(ids);
        this.$refs.batchSetInfoModalForm.title = this.$t('commodityManagement.batchEditing');
      }
    },
    handleEdit: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = this.$t('commodityManagement.edit');
      this.$refs.modalForm.disableSubmit = false;
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = true
      }
    },
    searchReset() {
      this.queryParam = {
        mpList: getMpListShort(Vue.ls.get('materialPropertyList'))  //扩展属性
      }
      this.loadData(1);
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>